<script setup>
import { useRouter } from 'vue-router';
const router = useRouter();
const handleClick = ()=>{
    router.back()
}

// 获取历史记录 ai-chat-assistant-messages
import { ref, onMounted } from 'vue';
import { useStorage } from '@vueuse/core';

const messages = ref([]);
const questions = ref([]);
const answers = ref([]);

onMounted(() => {
    // 假设历史记录存储在本地存储中，键名为 'ai-chat-assistant-messages'
    messages.value = useStorage('ai-chat-assistant-messages', []).value;
    messages.value.forEach((item,index) => {
        if(index>0){
            if(index%2==0){
                answers.value.push({
                    answer: item.content
                });
            }else{
                questions.value.push({
                    question: item.content
                });
            }
        }
    });
});


</script>

<template>
    <div class="history-page">
        <t-navbar class="my-header" title="我的提问" :fixed="false" left-arrow @left-click="handleClick" />
        <t-collapse v-for="(item, index) in questions" :key="index">
            <t-collapse-panel value="0" :header="item.question">
            <div class="content">
                答： {{answers[index].answer}}
            </div>
            </t-collapse-panel>
        </t-collapse>
    </div>
</template>

<style lang="scss" scoped>
.my-header {
    :deep(.t-navbar__content) {
        background-color: #07c160;
        color: #fff;
    }
}
</style>